package com.afdor.rws.dtm.core.entities;

import com.afdor.rws.annotation.extension.Extension;
import com.afdor.rws.dtm.entities.DistributedTransactionDefinition;
import com.afdor.rws.dtm.entities.DistributedTransactionInvocation;
import com.afdor.rws.dtm.transaction.ExecutionMode;
import com.afdor.rws.dtm.transaction.Isolation;
import com.afdor.rws.dtm.transaction.Propagation;
import com.afdor.rws.dtm.transaction.Status;
import lombok.Data;
import lombok.NonNull;

import java.io.Serializable;

/**
 * 默认事务定义信息实现
 *
 * @author 悭梵
 * @date Created in 2019-01-03 17:07
 */
@Data
@Extension(value = "default", scope = Extension.Scope.PROTOTYPE, order = Extension.NORMAL_ORDER - 100, interfaceClass = DistributedTransactionDefinition.class)
public class DefaultDistributedTransactionDefinition implements DistributedTransactionDefinition, Serializable, Cloneable {
    /**
     * 事务超时时间
     */
    private int timeout = 10 * 60 * 1000;
    /**
     * 只读事务
     */
    private boolean readOnly = Boolean.FALSE;
    /**
     * 事务隔离级别
     */
    @NonNull
    private Isolation isolation;
    /**
     * 事务传播性
     */
    @NonNull
    private Propagation propagation;
    /**
     * 事物执行方式
     */
    @NonNull
    private ExecutionMode executionMode;
    /**
     * 事务标识
     */
    @NonNull
    private String transactionId;
    /**
     * 事务对应执行器信息，通过aspectj反射获取生成
     */
    @NonNull
    private DistributedTransactionInvocation invocation;
    /**
     * 事务状态
     */
    @NonNull
    private Status status;

    @Override
    public DistributedTransactionDefinition setStatus(@NonNull Status status) {
        this.status = status;
        return this;
    }

}
